



let fs = require("fs")
let itemData = JSON.parse(fs.readFileSync("./cache/items_data.json").toString());
let itemCat = JSON.parse(fs.readFileSync("./cache/items.json").toString());
// console.log(str);
// let itemDataArr = Object.values(itemData);
// itemDataArr.sort((a, b) => {
//     return a.cost - b.cost
// });
let ItemsInfo = {};
for (let name in itemData) {
    itemData[name].name = name
    ItemsInfo[itemData[name].id] = itemData[name]
}

let enums = {
    basic: "基础",
    upgrade: "升级",
    neutral: "中立"
}
let Items = {}
for (let key in itemCat) {
    let info = itemCat[key]

    info.forEach(item2 => {
        let catName = item2.name;
        item2.items.forEach(item3 => {
            Items[item3.item_id] = {
                name: item3.name, catName, cat1: enums[key],
                notes: ItemsInfo[item3.item_id].notes,
                lore: ItemsInfo[item3.item_id].lore,
                attrib: deleteStrH(ItemsInfo[item3.item_id].attrib),
                desc: deleteStrH(ItemsInfo[item3.item_id].desc),
                name_cn: item3.name_loc,
                cost: item3.cost - 0,
            }
            if(ItemsInfo[item3.item_id].requirements) {
                Items[item3.item_id].requirements = ItemsInfo[item3.item_id].requirements.map(v3 => {
                    return  itemData[v3.replace("*", "")]?.dname || v3
                })
            }
        })
    })
}




fs.writeFileSync("./cache/itemInfos.json",JSON.stringify(Items))


function deleteStrH(str) {
    return str.replace(/<[^>]+>/ig, " ")
}